asm
  ld sp,$87FF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"

dim eee as uinteger at $8010
dim seed as uinteger at $8012
dim ee0 as uinteger at $8014
dim ee1 as uinteger at $8016
dim ee2 as uinteger at $8018
dim ee3 as uinteger at $801A
dim ee4 as uinteger at $801C
dim ee5 as uinteger at $801E
dim ex0 as uinteger at $8020
dim ey0 as uinteger at $8022


sub skyarmyputchar(txp1 as uinteger,typ1 as uinteger,tch1 as ubyte,tat1 as ubyte):
  poke $8800+(txp1 bxor 31)*32+typ1,tch1
  poke $9000+(txp1 bxor 31)*32+typ1,tat1
  end sub

sub skyarmyputspryte(tly1 as uinteger,txp1 as ubyte,typ1 as ubyte,tch1 as ubyte,tat1 as ubyte):
  end sub

for ee1=0 to 31
  for ee0=0 to 31
    ee3=seed:seed=smsrnd(seed)
    skyarmyputchar(ee0,ee1,seed band 3,ee3 band %00001111)
    poke $5800,$ff
    next:next

for ee1=0 to 15
  for ee0=0 to 15
    skyarmyputchar(ee0+14,ee1+15,ee1*16+ee0,0)
    poke $5800,$ff
    next:next



eee=0:ex0=8:ey0=8
do

skyarmyputchar(2,1,48+int(eee/10000) mod 10,0)
skyarmyputchar(3,1,48+int(eee/1000) mod 10,0)
skyarmyputchar(4,1,48+int(eee/100) mod 10,0)
skyarmyputchar(5,1,48+int(eee/10) mod 10,0)
skyarmyputchar(6,1,48+eee mod 10,0)

ee0=peek($A000)
skyarmyputchar(4,3,48+int(ee0/100) mod 10,0)
skyarmyputchar(5,3,48+int(ee0/10) mod 10,0)
skyarmyputchar(6,3,48+ee0 mod 10,0)

ee0=peek($A001)
skyarmyputchar(4,4,48+int(ee0/100) mod 10,0)
skyarmyputchar(5,4,48+int(ee0/10) mod 10,0)
skyarmyputchar(6,4,48+ee0 mod 10,0)

ey0=ey0-((ee0 band 1)/1)+((ee0 band 2)/2)
ex0=ex0-((ee0 band 4)/4)+((ee0 band 8)/8)

ee0=peek($A002)
skyarmyputchar(4,5,48+int(ee0/100) mod 10,0)
skyarmyputchar(5,5,48+int(ee0/10) mod 10,0)
skyarmyputchar(6,5,48+ee0 mod 10,0)

ee0=peek($A003)
skyarmyputchar(4,6,48+int(ee0/100) mod 10,0)
skyarmyputchar(5,6,48+int(ee0/10) mod 10,0)
skyarmyputchar(6,6,48+ee0 mod 10,0)


skyarmyputchar(ex0,ey0,eee,0)
poke $5800,$ff
eee=eee+1
loop


do:loop





for ee1=0 to 31
  for ee0=0 to 31
    ee3=seed:seed=smsrnd(seed)
    skyarmyputchar(ee0,ee1,seed,ee3)
    pacmandelay(20000)
    poke $5800,$ff
    next:next

do:loop








for ee1=0 to 31
  for ee0=0 to 31
    ee2=(ee0 bxor 31)*32+ee1
    ee3=seed:seed=smsrnd(seed)
    ee4=seed:seed=smsrnd(seed)
    ee3=seed:seed=smsrnd(seed)

    skyarmyputchar(ee0,ee1,seed,ee3)

    'poke $8C00+ee2,ee4 '- unknown
    'poke $8800+ee2,ee3 '- chr
    'poke $9000+ee2,seed '- attr

    poke $5800,$ff
    pacmandelay(20000)
    next:next

do:loop





for eee=$000 to $3FF
  seed=smsrnd(seed)
  poke $8800+eee,seed
  poke $8C00+eee,seed
  poke $9000+eee,seed
  poke $5800,$ff
  pacmandelay(1000)
  next

do:loop



seed=0

do

for eee=$8800 to $985F
  seed=smsrnd(seed)
  poke eee,seed
  poke $5800,$ff
  next

loop




'- static ADDRESS_MAP_START( skyarmy_map, AS_PROGRAM, 8, skyarmy_state )
'- AM_RANGE(0x0000, 0x7fff) AM_ROM
'- AM_RANGE(0x8000, 0x87ff) AM_RAM
'- AM_RANGE(0x8800, 0x8fff) AM_RAM_WRITE(videoram_w) AM_SHARE("videoram") /* Video RAM */
'- AM_RANGE(0x9000, 0x93ff) AM_RAM_WRITE(colorram_w) AM_SHARE("colorram") /* Color RAM */
'- AM_RANGE(0x9800, 0x983f) AM_RAM AM_SHARE("spriteram") /* Sprites */
'- AM_RANGE(0x9840, 0x985f) AM_RAM AM_SHARE("scrollram")  /* Scroll RAM */
'- AM_RANGE(0xa000, 0xa000) AM_READ_PORT("DSW")
'- AM_RANGE(0xa001, 0xa001) AM_READ_PORT("P1")
'- AM_RANGE(0xa002, 0xa002) AM_READ_PORT("P2")
'- AM_RANGE(0xa003, 0xa003) AM_READ_PORT("SYSTEM")
'- AM_RANGE(0xa004, 0xa004) AM_WRITE(nmi_enable_w) // ???
'- AM_RANGE(0xa005, 0xa005) AM_WRITE(flip_screen_x_w)
'- AM_RANGE(0xa006, 0xa006) AM_WRITE(flip_screen_y_w)
'- AM_RANGE(0xa007, 0xa007) AM_WRITENOP
'- ADDRESS_MAP_END
